<#include '/pages/taglib/core.ftl'>
<#include '/pages/taglib/common.ftl'>
<#include '/pages/taglib/container.ftl'>

<@script src="/static/espirit/scripts/espirit/eap/manager/menu.js"/>

<#assign _context = ps.reset().safeContext()>
<#if !includePage?exists>
	<#assign includePage = '/espirit/eap/manager/menu._add.ftl'>
</#if>

<@cs.include curpage=template_name genDir=true page=includePage>
	<style>
		.modelButtonTip {
			clear:both;
			padding: 5px;
			position: relative;
		}
		.modelButtonTitle {
			padding: 3px 0 5px 2px;
		}
		.modelButtonTitle .buttonTitle1 {
			display: inline-block;
		    width: 100px;
		}
		.modelButtonTitle .buttonTitle2 {
			display: inline-block;
		    width: 395px;
		}
		.modelButton {
			clear:both;
			padding-bottom: 5px;
			position: relative;
			width: 680px;
			overflow: hidden;
		}
		.modelButton .defaultSelect {
		    display: inline-block;
		    text-align: center;
		    width: 50px;
		}
		.modelButton .button, .jmenubutton {
			float: right;
    		margin-left: 5px;
		}
		.modelButton .modelPath {
			float: left;
			width: 400px;
			margin: 0;
		}
		.modelButton .methodLabel {
			width: 100px!important;
			margin: 1px 0 0!important;
			border: 0!important;
		}
		.modelButton .methodLabel input {
			width: 68px;
		}
		.modelButton .modelAccess {
			display: inline-block;
			width: 20px!important;
			padding-left: 5px;
		}
		
		.modelButton .errorPath {
			background: none repeat scroll 0 0 #FAD3C4;
		    color: #DD4B39;
		    font-size: 11px;
		    line-height: 12px;
		    white-space: nowrap;
		    display: inline-block;
		    float: right;
		    margin: 5px;
		    z-index: 99;
    	}
	</style>
	<script>
		when('eap_manager_menu',function() {
			menu_text = [];
			menu_text['model.espirit.eap.manager.menu.selectPath'] = '请输入路径';
			menu_text['model.espirit.eap.manager.menu.actPermission'] = '关闭权限控制';
			
			eap_manager_menu.initMenuPage();
		});
	</script>
	
	<@cs.extends target="name='parent.i18n'">
		<@combobox name='parent.id' label='model.espirit.eap.manager.menu.parent' labelProperty="i18n"
			url="/espirit/eap/manager/menu.searchParentMenu.html?_resultCode=$json&properties=totalCount,maxPageNo,data.id,data.i18n,data.firstChildPath"/>
	</@cs.extends>
	<@cs.extends target="name='page.path'">
	<#if actionName?string?ends_with('_updateAction')>
		<#assign method = '_update'>
	<#else>
		<style>.modelButton {width:600px}</style>
		<#assign method = '_add'>
	</#if>
	<span id="menuMethodCtn" style="display:block;clear:both">
		<div class="j-form-item stdEle">
			<label class="label"><@i18n name='model.espirit.eap.manager.menu.path'/>:</label>
			<span class="span modelButton" style="clear:none">
				<div class="modelButtonTitle">格式(/category/subcategory/model.method.html,xxx换为model名, subcategory为可选, 也可多级)</div><div class="clearBoth"></div>
				<@text name="page.path" clazz="modelPath" value=(model.page.path)! mask="^\\/(\\w*\\/)+\\w*\\.\\w*\\.html"/>
				<@checkbox name='page.freeAccess' clazz='modelAccess'/>
				
				<#if method='_update'>
					<@button label='action.updatePage' style="float:left" onclick='eap_manager_menu.gotoPageSetting(this)' url='/espirit/eap/pagelayout/page._addByPath.html'/>
				</#if>
			</span>
		</div>
		<div class="clearBoth"></div>
		
		<div class="pathCtn">
		<@hidden name='i18n.id'/>
		<@span name='model.paths' label="model.espirit.eap.manager.menu.subpath">
			<div class="modelButtonTitle">
				<span class= "buttonTitle1">名称(中文)</span>
				<span class= "buttonTitle2">路径</span>
				<span>自由访问</span>
			</div>
			
			<#if !model.relevantPages?exists>
				<#assign tmp = model.setRelevantPages([fn.newModel('com.espirit.eap.pagelayout.Page')])>
			</#if>
			<#assign i18nService = fn.service('espirit.eap.manager.i18n')>
			<#assign urlPrefix = '/espirit/eap/manager/menu.searchResource.html?_resultCode=$json&properties=totalCount,maxPageNo,data.key,data.value&type=method&path='>
			<#list model.relevantPages as page>
				<div class="modelButton">
					<@hidden name='relevantPages[' + page_index + '].id'/>
					<#-- method -->
					<@combobox name='relevantPages[' + page_index + '].i18n.id' labelName='relevantPages[' + page_index + '].i18n' url=urlPrefix + (model.page.path)!
							clazz='methodLabel' property="key" labelProperty="value" enableFreeText=true showMoreIcon=true/>
					
					<@text name='relevantPages[' + page_index + '].path' clazz='modelPath' mask="^\\/(\\w*\\/)+\\w*\\.\\w*\\.html" width=400/>
					<@checkbox name='relevantPages[' + page_index + '].freeAccess' clazz='modelAccess'/>
					<@button label='-' onclick='eap_manager_menu.removeMethod(this)'/>
					<@button label='+' onclick='eap_manager_menu.addMethod(this)'/>
					
					<#if method='_update'>
						<@button label='action.updatePage' onclick='eap_manager_menu.gotoPageSetting(this)' url='/espirit/eap/pagelayout/page._addByPath.html'/>
					</#if>
				</div>
			</#list>
		</@span>
		</div>
	</span>
	</@cs.extends>
</@cs.include>